/*
 * @Description: 将AppProviderContextProps属性全局注入 (provide & inject)
 * @Author: wangqi
 * @Date: 2024-05-11 10:17:29
 * @LastEditTime: 2024-06-15 11:52:18
 * @LastEditAuthor: wangqi
 */
import type { InjectionKey, Ref } from 'vue';
import { provide } from 'vue';
import { createContext, useContext } from '@/hooks/core/useContext';

export interface AppProviderContextProps {
  prefixCls: Ref<string>;
  isMobile: Ref<boolean>;
}

export const key: InjectionKey<AppProviderContextProps> = Symbol();

/* 将变量注入全局，但是这里的key变成了  */
export function createAppProviderContext(context: AppProviderContextProps) {
  return createContext<AppProviderContextProps>(context, key);
}

/* 使用上边注册的全局变量，则这里的key 不用关心, 只要知道返回值的类型是 AppProviderContextProps即可 */
export function useAppProviderContext() {
  return useContext<AppProviderContextProps>(key);
}

/* 测试 provide inject api功能 */
export function createAppWq(context) {
  provide('APP_WQHASH', context);
}
